package com.example.kotlineventtracker

import android.os.Bundle
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.kotlineventtracker.databinding.ActivityPageBinding
import com.example.kotlineventtracker.util.EventRepository
import com.example.kotlineventtracker.view.EventAdapter
import com.example.kotlineventtracker.viewmodel.EventViewModel

class PageActivity : AppCompatActivity() {
    private lateinit var binding: ActivityPageBinding
    private val viewModel: EventViewModel by viewModels()


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityPageBinding.inflate(layoutInflater)
        setContentView(binding.root)

        val pageId = intent.getStringExtra("pageId")
        val pageDesc = intent.getStringExtra("pageDesc")
        if (pageId != null && pageDesc != null) {
            binding.pageId.text = "页面ID: ${pageId}"
            binding.pageDesc.text = "页面名称: ${pageDesc}"
        }

        val adapter = EventAdapter(emptyList(),"module")
        binding.recyclerView.layoutManager = LinearLayoutManager(this)
        binding.recyclerView.adapter = adapter

        viewModel.events.observe(this, Observer { events ->
            binding.recyclerView.adapter = EventAdapter(events,"module")
        })

        viewModel.loadEvents("module",pageDesc.toString())
    }
}
